#include "kdcsubtitleeditorplugin.h"

#include <KPluginFactory>
#include <KPluginLoader>

class KDCSubtitleEditorPlugin;

#include <kdclib.h>
#include "kdcsubtitlesconfigpage.h"

#include <KLocale>

K_PLUGIN_FACTORY( KDCSubtitleEditorPluginFactory, registerPlugin< KDCSubtitleEditorPlugin >(); )
K_EXPORT_PLUGIN( KDCSubtitleEditorPluginFactory( "KDCSubtitleEditorPlugin" ) )

KDCSubtitleEditorPlugin::KDCSubtitleEditorPlugin( QObject *parent, const QVariantList &args ) : KDCPluginInterface( parent ), pInfo( KPluginInfo("kdcsubtitleeditorplugin.desktop", "services") ), pInterfaces( NULL ), pWidget( NULL )
{

}

KDCSubtitleEditorPlugin::~KDCSubtitleEditorPlugin()
{
	unload();
}

QString KDCSubtitleEditorPlugin::interfaceName() const
{
	return "KDCSubtitleEditorPlugin";
}

const KPluginInfo& KDCSubtitleEditorPlugin::info() const
{
	return pInfo;
}

QWidget* KDCSubtitleEditorPlugin::widget() const
{
	return pWidget;
}

KDCConfigPageInterface* KDCSubtitleEditorPlugin::configPage() const
{
	return new KDCSubtitlesConfigPage;
}

KDC::Position KDCSubtitleEditorPlugin::tabPosition() const
{
	return KDC::Bottom;
}

bool KDCSubtitleEditorPlugin::load()
{
	if ( pWidget )
		return false;
	pWidget = new KDCSubtitleWidget( this );
	return true;
}

bool KDCSubtitleEditorPlugin::unload()
{
	deletePtr( pWidget );
	return true;
}

bool KDCSubtitleEditorPlugin::setInterfaces( QList<KDCBaseInterface*>& aInterfaces )
{
	pInterfaces = &aInterfaces;
	return true;
}

bool KDCSubtitleEditorPlugin::init()
{
	foreach( KDCBaseInterface *interface, *pInterfaces )
		if ( interface->interfaceName() == "KDCDiscStructurePlugin" )
		{
			connect( static_cast<KDCPluginInterface*>( interface ), SIGNAL( objectChanged( KDCObject * ) ), this, SLOT( setObject( KDCObject * ) ) );
		}
	setObject( NULL );
	return true;
}

KDCObject* KDCSubtitleEditorPlugin::currentObject() const
{
	return NULL;
}

void KDCSubtitleEditorPlugin::setObject( KDCObject *aObject )
{
	if ( aObject && aObject->object() == KDC::Movie )
		pWidget->setMovie( static_cast<KDCMovie*>( aObject ) );
	else
		pWidget->setMovie( NULL );
}

void KDCSubtitleEditorPlugin::refresh()
{

}


#include "kdcsubtitleeditorplugin.moc"
